//////////////////////////////////////////////////////////////////////////////////
//
//	Invisible
//		- Version 1.2
//		- 04.18.2008
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
// - Running the command on clients will toggle their visibility
// - Defualt admin level is ADMIN_BAN
//
// COMMANDS: 
//	amx_invisible <nick | steam>	//Toggle invisibility on user
//	
// Changelog:
//
// - 02.11.2006 Version 1.0
//	Initial release
//
// - 07.09.2006 Version 1.1
//	Replaced ENGINE with FAKEMETA
//
// - 04.18.2008 Version 1.2
//	Cleaned up the code a little
//	Updated public cvar format
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define VERSION "1.2"
#define SVERSION "v1.2 - by diamond-optic (www.AvaMods.com)"

new invisible[33]

public plugin_init()
{
	register_plugin("Invisible",VERSION,"diamond-optic")
	register_cvar("amx_invisible_stats",SVERSION,FCVAR_SERVER|FCVAR_SPONLY)
	
	register_concmd("amx_invisible","invisibility",ADMIN_BAN,"<nick | steam> - toggle invisibility on user")
}

public client_putinserver(id)
	invisible[id] = 0
	
public invisibility(id,level,cid)
{
	if(!cmd_access(id,level,cid,0))
		return PLUGIN_HANDLED
	
	new readname[256]
	read_argv(1,readname,255)
	new playername = cmd_target(id,readname,2)
	
	if(!invisible[playername])	
		{
		invisible[playername] = 1
		fm_set_entity_visibility(playername,0)
		client_print(id,print_chat,"Invisiblilty turned ON for %s",playername)
		}
	else
		{
		invisible[playername] = 0
		fm_set_entity_visibility(playername,1)
		client_print(id,print_chat,"Invisibility turned OFF for %s",playername)
		}
			
	return PLUGIN_HANDLED
}

stock fm_set_entity_visibility(index,visible = 1)	//from fakemeta_util
{
	set_pev(index,pev_effects,visible == 1 ? pev(index, pev_effects) & ~EF_NODRAW : pev(index,pev_effects) | EF_NODRAW)

	return 1
}